﻿using System;
using System.IO;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Runtime.InteropServices;
using System.Threading;

namespace Eagleshoes.PackingBarcode
{
    public static class Program
    {
        public readonly static string DataPath = "\\ResidentFlash\\ErpData";

        public static readonly string DeliveryScan = DataPath + "\\出货扫描数据";

        public static readonly CartonService.CartonService CartonClient = new CartonService.CartonService();

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [MTAThread]
        private static void Main()
        {
           
            CreateDataDir();
            if (File.Exists(DataPath + "\\app.xml"))
            {
                XElement xRoot = XElement.Load(DataPath + "\\app.xml");
                var elem = xRoot.Element("serviceURL");
                if (elem != null)
                {
                    CartonClient.Url = elem.Value;
                }
            }
            CartonClient.Timeout = 10000;

            using (var sw = File.Open(".\\lock", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
            {
                Application.Run(new MainMenuForm());
            }
        }


        private static void CreateDataDir()
        {
            if (!Directory.Exists(DataPath))
            {
                Directory.CreateDirectory(DataPath);
            }
        }
    }
}